package se.hh.lab.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public final class JdbcUtil
{
	private static String user="root";
	private static String password="root"; 
	//private static String url="jdbc:sqlserver://localhost:1433;DatabaseName=lab";
	private static String url="jdbc:mysql://localhost:3306/lab";


	static
	{
		try
		{
			//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Class.forName("com.mysql.jdbc.Driver");	
		}
		catch (ClassNotFoundException e)
		{
			throw new ExceptionInInitializerError(e);	
		}
	}

	public static Connection getConnection() throws SQLException
	{
			return  DriverManager.getConnection(url,user,password);	
	}
	public static void free(ResultSet rs,Statement stmt,Connection con) throws SQLException
	{
		try{
			 if (rs != null)
				 rs.close();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}finally{	
			try{
				if (stmt != null)
					stmt.close();
			}catch(SQLException e)
			{
				e.printStackTrace();
			}finally{
				try{
					if (con != null)
						con.close();
					}catch(SQLException e)
						{
						e.printStackTrace();
						}
					}
				}
	}
}
